package sz.szsmk.citizencard.ui.fragment;

import android.annotation.SuppressLint;
import androidx.fragment.app.Fragment;

import android.view.View;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.BusHomeLineViewBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.model.network.bean.response.QueryBusLineNearbyRes;
import sz.szsmk.citizencard.mvp.contract.IBusHomeLineContact;
import sz.szsmk.citizencard.mvp.presenter.BusHomeLinePresenter;
import sz.szsmk.citizencard.ui.activity.BusHomeActivity;
import sz.szsmk.citizencard.ui.adapter.MyPagerAdapter;
import sz.szsmk.citizencard.ui.base.IBaseFragment;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/14 17:26
 * description:
 */
@SuppressLint("ValidFragment")
public class BusHomeLineFragment extends IBaseFragment<BusHomeLinePresenter, BusHomeLineViewBinding>
        implements IBusHomeLineContact.IBusHomeLineView, View.OnClickListener {

    private BusNearbyLineFragment busNearbyLineFragment;

    private List<Fragment> fragmentList = new ArrayList<>();
    private MyPagerAdapter myPagerAdapter;
    private String mLatitude;
    private String mLongitude;
    private List<QueryBusLineNearbyRes.BusLineArrayListBean> busLineArrayList = new ArrayList<>();


    public BusHomeLineFragment(BusHomeActivity busHomeActivity) {

    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.bus_home_line_view;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        dataBinding.busHomeLineLl.setOnClickListener(this);
        dataBinding.busHomeSiteLl.setOnClickListener(this);
//        busNearbyLineFragment = new BusNearbyLineFragment();
        fragmentList.add(BusNearbyLineFragment.getInstance());
        fragmentList.add(BusCollecLineFragment.getInstance());
//        fragmentList.add(busNearbyLineFragment);
        myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(), fragmentList);
        dataBinding.busHomeLineVp.setAdapter(myPagerAdapter);
        dataBinding.busHomeLineVp.setCurrentItem(0);
        setTextColor();
        dataBinding.lineTv1.setTextColor(getResources().getColor(R.color.color_00AAFF));
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void getSearchListSucc(QueryBusLineNearbyRes response) {
//        busLineArrayList = response.getBusLineArrayList();
//        BusNearbyLineFragment.getInstance().setViewData(busLineArrayList);
    }

    @Override
    public void getSearchListFail() {

    }

    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.bus_home_line_ll) {
            dataBinding.busHomeLineVp.setCurrentItem(0);
            setTextColor();
            dataBinding.lineTv1.setTextColor(getResources().getColor(R.color.color_00AAFF));
            dataBinding.lineIv1.setImageResource(R.drawable.icon_location_blue);
        } else if (id == R.id.bus_home_site_ll) {
            dataBinding.busHomeLineVp.setCurrentItem(1);
            setTextColor();
            dataBinding.lineTv2.setTextColor(getResources().getColor(R.color.color_00AAFF));
            dataBinding.lineIv2.setImageResource(R.drawable.icon_star_blue);
        }
    }

    private void setTextColor() {

        dataBinding.lineTv1.setTextColor(getResources().getColor(R.color.color_3d494f));
        dataBinding.lineTv2.setTextColor(getResources().getColor(R.color.color_3d494f));
        dataBinding.lineIv1.setImageResource(R.drawable.icon_location_grey);
        dataBinding.lineIv2.setImageResource(R.drawable.icon_star_grey);
    }
}
